package com.xiaobai.zhuangxiuguanjia.Utils;

import android.util.SparseArray;
import android.view.View;

/**
 * Created by Android Studio
 * Project: ZhuangXiuGuanJia
 * Author: Jack
 * Email: jackfangqi1314@gmail.com/jackfangqi@163.com
 * Date: 2015/6/16
 */
public class ViewHolder {
    private ViewHolder() {
    }

    public static <T extends View> T getView(View view, int id) {
        SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
        if (viewHolder == null) {
            viewHolder = new SparseArray<>();
            view.setTag(viewHolder);
        }

        View childView = viewHolder.get(id);
        if (childView == null) {
            childView = view.findViewById(id);
            viewHolder.put(id, childView);
        }

        return (T) childView;
    }
}
